/**
 * 排行榜管理器
 */
class RankManager {
	public constructor() {
	}

	private static _instance:RankManager;
	public static instance():RankManager{
		if(!RankManager._instance){
			RankManager._instance = new RankManager();
		}
		return RankManager._instance;
	}

	private _worldUserData:Dictionary<any[]> = new Dictionary<any[]>();
	public get worldUserData(){
		return this._worldUserData;
	}
	public addUserInfo(value:any, key:number){
		let list = this._worldUserData.getValueByKey(key);
		if(!list){
			list = [];
			this._worldUserData.add(key, list);
		}
		list.push(value);
	}

	/**
	 * 上传用户分数到微信后台
	 */
	public uploadUserScore(score:number, type:string){
		let value = JSON.stringify({
				wxgame:{
					score:score,
					update_time:TimeUtil.getTimeStamp()
				},
				cost_ms:1000
			});

        WeChatgGameManager.instance().setUserDataToCould([{
			key:type,
			value:value
		}]);
	}

	/**
	 * 请求排行榜玩家数据
	 */
	public postWorldUserData(mapID:number = 0, page:number = 1, call?, scope?){
		
	}

	/**
	 * 更新玩过的微信好友数据
	 */
	public loadFriendCloudStorage(){
        WeChatgGameManager.instance().sendMessageToOpen({
            command:'loadRes'
        });
	}

	/**
	 * 更新玩过的微信好友数据
	 */
	public updateFriendCloudStorage(){
        WeChatgGameManager.instance().sendMessageToOpen({
            command:'open'
        });
	}

	/**
	 * 请求微信好友数据
	 */
	public requestFriendCloudStorage(type){
        WeChatgGameManager.instance().sendMessageToOpen({
            command:type
        });
	} 

	/**
	 * 更新玩过的微信好友数据
	 */
	public closeFriendCloudStorage(){
        WeChatgGameManager.instance().sendMessageToOpen({
            command:'close'
        });
	}

	/**
	 * 请求下一页数据
	 */
	public requestNextPageData()
	{
		WeChatgGameManager.instance().sendMessageToOpen({
            command:'nextPage'
        });
	}

	/**
	 * 请求上一页数据
	 */
	public requestLastPageData()
	{
		WeChatgGameManager.instance().sendMessageToOpen({
            command:'lastPage'
        });
	}

	/**
	 * 获取即将超越的好友
	 */
	public getBeyondFriendData(score)
	{
		WeChatgGameManager.instance().sendMessageToOpen({
            command:'showFriendReadyToBeyond',
			score:score
        });
	}

		/**
	 * 获取自己排名附近的好友
	 */
	public showNearlyFriendRank()
	{
		WeChatgGameManager.instance().sendMessageToOpen({
            command:'showNearlyFriendRank',
        });
	}
}